import 'package:flutter/material.dart';

class Anniversary {
  final String id;
  final String title;
  final DateTime date;
  final bool isYearly;
  final Color color;

  Anniversary({
    required this.id,
    required this.title,
    required this.date,
    this.isYearly = false,
    this.color = Colors.pink,
  });

  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'title': title,
      'date': date.toIso8601String(),
      'isYearly': isYearly,
      'color': color.value,
    };
  }

  factory Anniversary.fromJson(Map<String, dynamic> json) {
    return Anniversary(
      id: json['id'],
      title: json['title'],
      date: DateTime.parse(json['date']),
      isYearly: json['isYearly'],
      color: Color(json['color']),
    );
  }

  int get daysRemaining {
    final now = DateTime.now();
    final anniversary = DateTime(now.year, date.month, date.day);

    if (anniversary.isBefore(now)) {
      if (isYearly) {
        final nextAnniversary = DateTime(now.year + 1, date.month, date.day);
        return nextAnniversary.difference(now).inDays;
      } else {
        return 0;
      }
    }

    return anniversary.difference(now).inDays;
  }
}

